<?php
function getCategory($parentID=0)
{
    mysql_connect("localhost", "webviet_user", "Mnbvc117") or
    die("Lỗi kết nối Database: " . mysql_error());
    mysql_select_db("webviet_wt");
    
    mysql_query("SET NAMES 'utf8'");
    $result = mysql_query("SELECT * FROM mid_categories WHERE parent_id = ".$parentID);
    
    $categoryData = array();
    while ($row = mysql_fetch_array($result)) {
        $categoryData['id'][] = $row['id'];
        $categoryData['category_name'][] = $row['category_name'];
    }
    mysql_free_result($result);
    return $categoryData;
}

if(isset($_POST['id']) && isset($_POST['level']) && isset($_POST['nav'])){
    $arr = getCategory($_POST['id']);
    if($arr!=null){
        echo '<hr /><div class="level'.$_POST['level'].'"><ul>';
        echo "<p class='navtitle'>".$_POST['nav']."</p>";
        for($i=0;$i<count($arr['id']);$i++){
            //echo $arr['id'][$i].','.$arr['category_name'][$i].';';
            ?>
            <li>
            <input name="category_id_" class="rlevel<?php echo $_POST['level']; ?>" id="<?php echo $arr['id'][$i]; ?>" type="radio" onclick="javascript:getSubCat(<?php echo $arr['id'][$i]; ?>,<?php echo $_POST['level']+1; ?>,'<?php echo $_POST['nav']." >> ".$arr['category_name'][$i]; ?>');" value="<?php echo $arr['id'][$i]; ?>" />
            <label for="<?php echo $arr['id'][$i]; ?>"><?php echo $arr['category_name'][$i]; ?></label>
            </li>
            <?php
        }
        echo '</ul></div>';
    }
}else{
    echo 'error';
}